function NewChrom=xovmp(OldChrom,Px,Npt,Rs)
[Nind,Lind]=size(OldChrom);
Xops=floor(Nind/2);
DoCross=rand(Xops,1)<Px;
odd=1:2:Nind-1;
even=2:2:Nind;
Mask=~Rs|(OldChrom(odd,:)~=OldChrom(even,:));
Mask=cumsum(Mask')';
xsites(:,1)=Mask(:,Lind);
if Npt>=2,
    xsites(:,1)=ceil(xsites(:,1).*rand(Xops,1));
end
xsites(:,2)=rem(xsites+ceil((Mask(:,Lind)-1).*rand(Xops,1))...
                                                       .*DoCross-1,Mask(:,Lind))+1;
Mask=(xsites(:,ones(1,Lind))<Mask)==...
                                           (xsites(:,2*ones(1,Lind))<Mask);
if ~Npt,
    shuff=rand(Lind,Xops);
    [ans,shuff]=sort(shuff);
    for i=1:Xops
        OldChrom(odd(i),:)=OldChrom(odd(i),shuff(:,i));
        OldChrom(even(i),:)=OldChrom(even(i),shuff(:,i));
    end
end
NewChrom(odd,:)=(OldChrom(odd,:).*Mask)+(OldChrom(even,:).*(~Mask));
NewChrom(even,:)=(OldChrom(odd,:).*(~Mask))+(OldChrom(even,:).*Mask);
if rem(Nind,2),
    NewChrom(Nind,:)=OldChrom(Nind,:);
end
if ~Npt,
    [ans,unshuff]=sort(shuff);
for i=1:Xops
    NewChrom(odd(i),:)=NewChrom(odd(i),unshuff(:,i));
    NewChrom(even(i),:)=NewChrom(even(i),unshuff(:,i));
end
end
end